gh-116772: Cache getenv result in optimizer.c to reduce calls#126439
Closed
Wulian233 wants to merge 5 commits intopython:mainfrom
Closed
gh-116772: Cache getenv result in optimizer.c to reduce calls#126439Wulian233 wants to merge 5 commits intopython:mainfrom
getenv result in optimizer.c to reduce calls#126439Wulian233 wants to merge 5 commits intopython:mainfrom
Conversation
Python/optimizer.c
Outdated
Comment on lines
+1228
to
+1229
| static int uop_optimize_initialized = 0; | ||
| static int uop_optimize_flag = 0; |
Member
There was a problem hiding this comment.
This isn't thread safe or subinterpreter safe. You might want to store the value in a PyThreadState / PyInterpreterState in pylifecycle.c instead.
Member
|
@mdboom did you have a change planned for this? |
Contributor
No, I don't have a plan. Thanks to @Wulian233 for taking this on. |
| initialize_uops_optimize_flag(void) { | ||
| if (!uops_optimize_initialized) { | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE"); |
Member
There was a problem hiding this comment.
Can you please do this instead at where we check for PYTHON_JIT ? So in pylifecycle.c.
Set the thread state/interp state there as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is my first time PR for part C, which looks like it might be a small improvement, hopefully I'm not doing anything wrong🙂
About 0.5% faster? (from issue)
getenvon every optimization run #116772